<template>
  <div>
    <el-dialog title="编辑" :visible.sync="editDialog.show">
      <el-form :model="editDialog.data" size="small" :rules="rules" ref="ruleForm" :label-width="formLabelWidth"> 
        <el-form-item label="姓名"  prop="username">
          <el-input v-model="editDialog.data.username"  clearable></el-input>
        </el-form-item>
        <el-form-item label="密码"  prop="password">
          <el-input v-model="editDialog.data.password" clearable></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialog.show = false" size="small">取 消</el-button>
        <el-button type="primary" @click="onSubmit" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import api from '@/api'
export default {
  props: {
    editDialog: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formLabelWidth: "140px",
      rules: {
        username: [{ required: true, message: "请输入用户名", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  methods: {
    onSubmit() {
      this.$refs["ruleForm"].validate(valid => {
        if (valid) {
            this.onSubmitConfim()
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    //确定提交
    onSubmitConfim() {
      var obj={
          id:this.editDialog.data.id,
          password:this.editDialog.data.password,
          username:this.editDialog.data.username,
      }
      api.editUser(obj)
      .then(res=>{
        if(res.code===200){
          this.$message.success('操作成功！')
          this.$emit('editSuccess')
          this.editDialog.show=false
        }else{
          this.$alert(res.msg, "提示", {
              confirmButtonText: "确定",
              type:'warning'
            });

        }
      })
      .catch(err => {
          this.loading=false
          this.$alert(err, "系统错误", {
            confirmButtonText: "确定",
            type:'error'
          });
        });

    }
  }
};
</script>
